<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BConfig
 *
 * @author ID59C
 */
class BConfig extends BAttribute {
     
    public function getRepository($data = NULL, $reload = FALSE) {
        $repository = parent::getRepository($data, $reload);
        $repository->setModel('BMConfig');
        return $repository;
    }

    public function getConfigValue($data = NULL) {
        return $this->getValue($data);
    }

    /**
     * 
     * @param type $context
     * @return BConfig
     */
    public function getConfig($context = NULL) {
        return $this->getChild($context);
    }

    /**
     * 
     * @param type $context
     * @return array
     */
    public function getConfigList($context = NULL) {
        return $this->getChildren($context);
    }

    public function addConfig($config) {
        return $this->addChild($config);
    }

    public function addConfigInArray($configsInArray, $configContext = NULL) {

        if (!is_array($configsInArray))
            return FALSE;

        foreach ($configsInArray as $key => $value) {
            if (!is_array($value)) {
                if (is_string($key)) {
                    $child = clone $this;
                    $child->name = $key;
                    $child->value = $value;
                    $child->id = NULL;
                    $this->addChild($child);
                } else {
                    $child = clone $this;
                    $child->name = $value;
                    $child->value = NULL;
                    $child->id = NULL;
                    $this->addChild($child);
                }
            } else {
                $name = $key;
                $value = key($value);
                if (is_string($value)) {
                    $child = clone $this;
                    $child->name = $key;
                    $child->value = $value;
                    $child->id = NULL;
                    $child = $this->addChild($child);
                }
                $child->addConfigInArray($value, $configContext);
            }
        }
    }

}

?>
